package sdfi.lee.Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sdfi.lee.DAO.UserDAO;

/**
 * Servlet implementation class AddRss
 */
public class AddRss extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddRss() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String rolltype=request.getParameter("rolltype");
		String keyword=request.getParameter("keyword");
		String typename=request.getParameter("typename");
		System.out.println(typename);
		String userid=request.getSession().getAttribute("userid").toString();
		String flag="{\"status\":\"error\"}";
		try
		{
		if(!(rolltype==null||keyword==null||userid==null))
		{
			sdfi.lee.Entity.Character mycharacter=new sdfi.lee.Entity.Character();
			mycharacter.getRolltype().setId(Integer.valueOf(rolltype));
			mycharacter.getUserid().setId(Integer.valueOf(userid));
			mycharacter.setKeyword(keyword);
			mycharacter.getRolltype().setTypename(typename);
			String f=new UserDAO().addRss(mycharacter);
			if(!"success".equals(f)&&!"error".equals(f))
					
					flag="{\"status\":\"success\",\"id\":\""+f+"\"}";
					
			}
	
		}
		catch(Exception ee)
		{
		
			System.out.println("Exception when you add rss");
			ee.printStackTrace();
		}
	//	System.out.println(flag);
		PrintWriter pw=response.getWriter();
		pw.append(flag);
		pw.flush();
		pw.close();
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(request, response);
	}

}
